//
// Created by sjjmw on 3/24/2022.
//

//应该使用dfs

#include "iostream"
#include "vector"
#include "list"
#include "algorithm"
#include "string"
#include "unordered_map"
#include "cmath"
#include<iomanip>
#include "string"
#include "map"
#include "list"
struct Sol{
    std::vector<int> mgs;
    int tar;
    int tar_cnt;
    std::vector<char> selected;
    int match_cnt=0;
    void dfs(int begin,int sum_len){

        if(sum_len>tar){
            //超出目标长
            return;
        }else if(sum_len==tar){
            sum_len=0;
        }
        for(int i=0;i<mgs.size();i++){
            if(!selected[i]){

                selected[i]=1;
                if(sum_len+mgs[i]==tar){
                    match_cnt++;
                }
//                if(i>0&&mgs[i]==mgs[i-1]){continue;}
                dfs(begin+1,sum_len+mgs[i]);
                if(match_cnt==tar_cnt){
                    return;
                }
                if(sum_len+mgs[i]==tar){
                    match_cnt--;
                }
                selected[i]=0;
            }
        }
    }
    void handle(
            //n张，k种
            int n
            ){
        mgs.resize(n);
        selected.resize(n);
        int sum_len=0;
        for (int i = 0; i < n; ++i) {
            std::cin>>mgs[i];
            sum_len+=mgs[i];
        }
        std::sort(mgs.begin(),mgs.end(),
                  std::greater<int>());
        for(int i=mgs[0];i<=sum_len;i++){
            if(sum_len%i==0){
                tar=i;
                tar_cnt=sum_len/i;
                match_cnt=0;
                dfs(0,0);
                if(match_cnt==tar_cnt){
                    break;
                }
            }
        }
        printf("%d\n",tar);
        ;
    }
};
int main(){
    int a,b,c;
//    float a,b,c,d;
    int e;
    while(std::cin>>a){
        if(a==0){
            break;
        }
        Sol().handle(a);

//        Sol().handle(a,b);
    }

    return 0;
}